package kessai;

import shouhin.ShouhinBeans;

import java.util.ArrayList;

public class CartBeans {

	private String				tyuumon_id; // 注文データ
	private ArrayList<ShouhinBeans>	items;	// 商品データ
	private int					sougoukei;	//総合計
	private int					syoukei;	//小計
	private double				syouhizei;	//消費税

	//コンストラクタ　値を初期化
	public CartBeans(){
		tyuumon_id = "";
		items = new ArrayList<ShouhinBeans>();
		sougoukei = 0;
		syoukei = 0;
		syouhizei = 0;
	}

	//カートに商品を追加
	public void addItem(ShouhinBeans item){

		items.add(item);
		this.syoukei = item.getSyoukei();
		this.syouhizei = syoukei * 0.05;
		this.sougoukei = syoukei + (int)syouhizei;

	}

	//選択した商品の個数を変更
	public void ChangeKosuu(int syouhin_id, int kosuu){

		for(int i=0; i<items.size(); i++){
			ShouhinBeans tBean = items.get(i);

			if(syouhin_id == tBean.getSyouhin_id()){
				tBean.setKosuu(kosuu);
			}
		}
	}
	//選択したsyouhin_idの商品をカートから削除
	public void deleteItem(int syouhin_id){
		for(int i=0; i<items.size(); i++){
			ShouhinBeans tBean = items.get(i);

			if(syouhin_id == tBean.getSyouhin_id()){
				items.remove(i);
			}
		}
	}
	//注文番号
	public String getTyuumon_id() {
		return tyuumon_id;
	}

	//注文番号のセット
	public void setTyuumon_id(String tyuumon_id) {
		this.tyuumon_id = tyuumon_id;
	}

	//商品の取得
	public ArrayList<ShouhinBeans> getItems(){
		return items;
	}
	//総合計の取得
	public int getSougoukei() {
		return sougoukei;
	}
	//総合計の格納
	public void setSouboukei(int sougoukei) {
		this.sougoukei = sougoukei;
	}

	public int getSyoukei() {
		return syoukei;
	}

	public void setSyoukei(int syoukei) {
		this.syoukei = syoukei;
	}

	public double getSyouhizei() {
		return syouhizei;
	}

	public void setSyouhizei(double syouhizei) {
		this.syouhizei = syouhizei;
	}


}
